package top.superflow.flow.load

import java.io.File

import top.superflow.exception.RequestUnsupportedException
import top.superflow.lang.StringUtils

object FlowPathUtils {


  def getRootPath = getClass.getResource("/").getPath

  def getResourcePath (relativePath : String) : String = {
    if(StringUtils.isBlank(relativePath)){
      throw new RequestUnsupportedException("Please don't pass blank relative path")
    }

    val fullPath = getRootPath + relativePath
    if(! new File(fullPath).exists()){
      throw new RequestUnsupportedException("Please pass the correct existing relative path under " + getRootPath)
    }

    return fullPath
  }


  def getResourceFile (rootDir : String, relativePath : String) : File = {
    if(StringUtils.isBlank(rootDir) || StringUtils.isBlank(relativePath)){
      throw new RequestUnsupportedException("Please don't pass blank rootDir or relative path")
    }

    val fullPath = rootDir + "/"+ relativePath
    val fullPathFile = new File(fullPath)
    if(! fullPathFile.exists()){
      throw new RequestUnsupportedException("Please pass the correct root dir " + rootDir + " and relative path " + relativePath)
    }

    return fullPathFile
  }
}
